package blog.web.app.listener;

import pub.functions.PropsFuncs;
import pub.functions.StrFuncs;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * describe: Created by IntelliJ IDEA.
 * @author zzl
 * @version 2010-2-9
 */
public class AppListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {
        ServletContext sc = event.getServletContext();
//		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);

        sc.setAttribute("home", sc.getContextPath());

        //
        initMdEnvironment();
    }

    private void initMdEnvironment() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        String jdbcUrl = PropsFuncs.getProperty("sys", "md_jdbc_url");
        if(StrFuncs.isEmpty(jdbcUrl)) {
            jdbcUrl = PropsFuncs.getProperty("sys", "jdbc_url");
        }
    }

    public void contextDestroyed(ServletContextEvent event) {
    }
}
